package com.example.mapper;

import com.example.pojo.AdminArticle;
import com.example.pojo.Article;
import com.example.pojo.ArticleList;
import com.example.pojo.admin.SearchBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Description TODO
 * @Author fantasy
 * @Date 2024/7/4 21:53
 **/

@Mapper
public interface ArticleMapper {

    @Insert("insert into article (title,content,cover_img,state,category_id,create_user,create_time,update_time)" +
            "values (#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},now(),now())")
    void add(Article article);

    List<ArticleList> list(@Param("userId") Integer userId, @Param("categoryId") Integer categoryId, @Param("state") String state);

    List<ArticleList> getList(@Param("categoryId") Integer categoryId, @Param("state") String state,@Param("userId") Integer userId);

    AdminArticle getArticleById(Integer id);

    @Update("update article set title = #{title},content = #{content},cover_img = #{coverImg},state = #{state},category_id = #{categoryId},update_time = now() where id = #{id}")
    void update(Article article);

    @Update("update article set active = 0 where id = #{id}")
    void delete(Integer id);

    List<AdminArticle> getAllList();

    @Update("update article set active = 1 where id = #{id}")
    void revoke(Integer id);

    List<AdminArticle> getLikeList(SearchBean searchBean);
}
